home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Container / Sources / Select.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  25.4 KB  |  841 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Select.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Container.hpp"
  11.  
  12. #ifndef SELECT_H
  13. #include "Select.h"
  14. #endif
  15.  
  16. #ifndef CONTENT_H
  17. #include "Content.h"
  18. #endif
  19.  
  20. #ifndef PART_H
  21. #include "Part.h"
  22. #endif
  23.  
  24. #ifndef FRAME_H
  25. #include "Frame.h"
  26. #endif
  27.  
  28. #ifndef PROXY_H
  29. #include "Proxy.h"
  30. #endif
  31.  
  32. #ifndef COMMANDS_H
  33. #include "Commands.h"
  34. #endif
  35.  
  36. #ifndef TRACKER_H
  37. #include "Tracker.h"
  38. #endif
  39.  
  40. // ----- Part Layer -----
  41.  
  42. #ifndef FWPRESEN_H
  43. #include "FWPresen.h"
  44. #endif
  45.  
  46. #ifndef FWITERS_H
  47. #include "FWIters.h"
  48. #endif
  49.  
  50. #ifndef FWCONTXT_H
  51. #include "FWContxt.h"
  52. #endif
  53.  
  54. #ifndef FWFCTCLP_H
  55. #include "FWFctClp.h"
  56. #endif
  57.  
  58. // ----- OS Layer -----
  59.  
  60. #ifndef FWODGEOM_H
  61. #include "FWODGeom.h"
  62. #endif
  63.  
  64. #ifndef SLMixOS_H
  65. #include "SLMixOS.h"
  66. #endif
  67.  
  68. // ----- OpenDoc Includes -----
  69.  
  70. #ifndef SOM_ODShape_xh
  71. #include <Shape.xh>
  72. #endif
  73.  
  74. #ifndef SOM_ODStorageUnit_xh
  75. #include <StorageU.xh>
  76. #endif
  77.  
  78. #ifndef SOM_Module_OpenDoc_StdProps_defined
  79. #include <StdProps.xh>
  80. #endif
  81.  
  82. //========================================================================================
  83. // Runtime Information
  84. //========================================================================================
  85.  
  86. #ifdef FW_BUILD_MAC
  87. #pragma segment odfcontainer
  88. #endif
  89.  
  90. //========================================================================================
  91. //    class CContainerSelection
  92. //========================================================================================
  93.  
  94. FW_DEFINE_AUTO(CContainerSelection)
  95.  
  96. //----------------------------------------------------------------------------------------
  97. //    CContainerSelection::CContainerSelection
  98. //----------------------------------------------------------------------------------------
  99.  
  100. CContainerSelection::CContainerSelection(Environment* ev, CContainerPart* part):
  101.     FW_CSelection(ev, false, false),    // no linking allowed
  102.     fContainerPart(part),
  103.     fUpdateShape(NULL),
  104.     fCount(0),
  105.     fSelectionContent(NULL),
  106.     fWorkingHandle(FW_kZeroRect, FW_kFill),
  107.     fDraggedContent(NULL)
  108. {
  109.     fSelectionContent = FW_NEW(CSelectionContent, (ev, part, this));
  110.     fWorkingHandle.SetInk(FW_kInvertInk);
  111.     FW_END_CONSTRUCTOR
  112. }
  113.  
  114. //----------------------------------------------------------------------------------------
  115. //    CContainerSelection::~CContainerSelection
  116. //----------------------------------------------------------------------------------------
  117.  
  118. CContainerSelection::~CContainerSelection()
  119. {
  120.     FW_START_DESTRUCTOR
  121.     if (fUpdateShape)
  122.     {
  123.         FW_SOMEnvironment ev;
  124.         fUpdateShape->Release(ev);
  125.     }
  126.     
  127.     delete fSelectionContent;
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. //    CContainerSelection::GetSelectedContent
  132. //----------------------------------------------------------------------------------------
  133.  
  134. FW_CContent* CContainerSelection::GetSelectedContent(Environment* ev)
  135. {
  136. FW_UNUSED(ev);
  137.     return fSelectionContent;
  138. }
  139.  
  140. //----------------------------------------------------------------------------------------
  141. //    CContainerSelection::WhichHandle
  142. //----------------------------------------------------------------------------------------
  143.  
  144. CProxy* CContainerSelection::WhichHandle(Environment* ev, 
  145.                                         FW_CGraphicContext& gc, 
  146.                                         const FW_CPoint& mouse, 
  147.                                         short& whichHandle,
  148.                                         FW_Fixed zoomFactor) const
  149. {
  150. FW_UNUSED(ev);
  151.     whichHandle = 0;
  152.     
  153.     if (fCount != 0)
  154.     {
  155.         CContentProxyIterator ite(fSelectionContent);
  156.         for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  157.         {
  158.             whichHandle = proxy->WhichHandle(gc, mouse, zoomFactor);
  159.             if (whichHandle != 0)
  160.                 return proxy;
  161.         }
  162.     }
  163.     
  164.     return NULL;
  165. }
  166.  
  167. //----------------------------------------------------------------------------------------
  168. //    CContainerSelection::RenderSelectionHandles
  169. //----------------------------------------------------------------------------------------
  170.  
  171. void CContainerSelection::RenderSelectionHandles(Environment* ev, FW_CGraphicContext& gc, FW_Fixed zoomFactor)
  172. {
  173. FW_UNUSED(ev);
  174.     CContentProxyIterator ite(fSelectionContent);
  175.     for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  176.     {
  177.         proxy->RenderHandles(gc, zoomFactor);    
  178.     }
  179. }
  180.  
  181. //----------------------------------------------------------------------------------------
  182. //    CContainerSelection::InvalidateSelectionHandles
  183. //----------------------------------------------------------------------------------------
  184.  
  185. void CContainerSelection::InvalidateSelectionHandles(Environment* ev, CContainerFrame* frame)
  186. {
  187.     FW_CSuperView* contentView = frame->GetContentView(ev);
  188.     FW_CAcquiredODShape workingShape1 = FW_NewODShape(ev);
  189.     FW_CAcquiredODShape workingShape2 = FW_NewODShape(ev);
  190.     CContentProxyIterator ite(fSelectionContent);
  191.     FW_Fixed penSize = CalcHandlePenSize(frame->GetZoomFactor());
  192.     for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  193.     {
  194.         proxy->InvalidateHandles(ev, contentView, workingShape1, workingShape2, penSize);
  195.     }
  196. }
  197.  
  198. //----------------------------------------------------------------------------------------
  199. //    CContainerSelection::RenderAllHandles
  200. //----------------------------------------------------------------------------------------
  201.  
  202. void CContainerSelection::RenderAllHandles(Environment* ev, CContainerFrame* frame)
  203. {
  204.     if (fCount != 0)
  205.     {        
  206.         FW_CFrameFacetIterator ite(ev, frame);
  207.         for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
  208.         {
  209.             FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
  210.             RenderSelectionHandles(ev, vc, frame->GetZoomFactor());
  211.         }
  212.     }
  213. }
  214.  
  215. //----------------------------------------------------------------------------------------
  216. //    CContainerSelection::RenderHandles
  217. //----------------------------------------------------------------------------------------
  218.  
  219. void CContainerSelection::RenderHandles(Environment* ev, CProxy* proxy)
  220. {
  221.     FW_CPresentationFrameIterator ite(ev, GetPresentation(ev));
  222.     for (CContainerFrame* frame = (CContainerFrame*)ite.First(ev); ite.IsNotComplete(ev); frame = (CContainerFrame*)ite.Next(ev))
  223.     {
  224.         if (frame->HasSelectionFocus(ev))
  225.         {
  226.             // ODFrame::SetInLimbo(true) can trigger this, on a detached frame, which has no window!
  227.             FW_CWindow* window = frame->GetWindow(ev);
  228.             if (window && window->IsActive(ev))
  229.             {
  230.                 FW_CFrameFacetIterator i(ev, frame);            
  231.                 for (ODFacet* facet = i.First(ev); i.IsNotComplete(ev); facet = i.Next(ev))
  232.                 {
  233.                     FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
  234.                     proxy->RenderHandles(vc, frame->GetZoomFactor());
  235.                 }
  236.             }
  237.         }
  238.     }
  239. }
  240.  
  241. //----------------------------------------------------------------------------------------
  242. //    CContainerSelection::CloseSelection
  243. //----------------------------------------------------------------------------------------
  244.  
  245. void CContainerSelection::CloseSelection(Environment* ev)
  246. {
  247.     CProxy* proxy;
  248.     while ((proxy = fSelectionContent->GetFirstProxy()) != NULL)
  249.     {
  250.         DoRemove(ev, proxy);
  251.         RenderHandles(ev, proxy);        // turn off
  252.     }
  253. }
  254.  
  255. //----------------------------------------------------------------------------------------
  256. //    CContainerSelection::AddToSelection
  257. //----------------------------------------------------------------------------------------
  258.  
  259. void CContainerSelection::AddToSelection(Environment* ev, CProxy* theProxy, FW_Boolean renderHandles)
  260. {                
  261.     if (theProxy != NULL)
  262.     {
  263.         DoAdd(ev, theProxy);
  264.         if (renderHandles)
  265.             RenderHandles(ev, theProxy);    // Turn on    
  266.     }        
  267. }
  268.  
  269. //----------------------------------------------------------------------------------------
  270. //    CContainerSelection::RemoveFromSelection
  271. //----------------------------------------------------------------------------------------
  272.  
  273. void CContainerSelection::RemoveFromSelection(Environment* ev, CProxy* proxy, FW_Boolean renderHandles)
  274. {                
  275.     if (proxy != NULL)
  276.     {
  277.         DoRemove(ev, proxy);
  278.         if (renderHandles)
  279.             RenderHandles(ev, proxy);        // Turn Off
  280.     }    
  281. }
  282.  
  283. //----------------------------------------------------------------------------------------
  284. //    CContainerSelection::DoAdd
  285. //----------------------------------------------------------------------------------------
  286.  
  287. void CContainerSelection::DoAdd(Environment* ev, CProxy* proxy)
  288. {
  289.     fSelectionContent->AddProxy(ev, proxy);
  290.     this->ProxyAdded(ev, proxy);
  291. }
  292.  
  293. //----------------------------------------------------------------------------------------
  294. //    CContainerSelection::ProxyAdded
  295. //----------------------------------------------------------------------------------------
  296.  
  297. void CContainerSelection::ProxyAdded(Environment* ev, CProxy* proxy)
  298. {
  299.     proxy->SelectProxy(ev, true);
  300.     fCount++;
  301.     
  302.     ClearCache(ev);
  303. }
  304.  
  305. //----------------------------------------------------------------------------------------
  306. //    CContainerSelection::DoRemove
  307. //----------------------------------------------------------------------------------------
  308.  
  309. void CContainerSelection::DoRemove(Environment* ev, CProxy* proxy)
  310. {
  311.     proxy->SelectProxy(ev, false);
  312.     fCount--;
  313.     
  314.     fSelectionContent->RemoveProxy(ev, proxy);
  315.     
  316.     ClearCache(ev);
  317. }
  318.  
  319. //----------------------------------------------------------------------------------------
  320. //    CContainerSelection::ClearSelection
  321. //----------------------------------------------------------------------------------------
  322.  
  323. void CContainerSelection::ClearSelection(Environment* ev)
  324. {
  325.     FW_CAcquiredODShape updateShape = GetUpdateShape(ev)->Copy(ev);
  326.     
  327.     CProxy* proxy;
  328.     while ((proxy = fSelectionContent->GetFirstProxy()) != NULL)
  329.     {
  330.         DoRemove(ev, proxy);                        // Remove from selection list
  331.         fContainerPart->DetachProxy(ev, proxy);        // Remove from part
  332.     }
  333.     
  334.     FW_CFacetClipper facetClipper;
  335.     facetClipper.Clip(ev, GetPresentation(ev), updateShape);
  336.     GetPresentation(ev)->Invalidate(ev, updateShape);
  337. }
  338.  
  339. /*----------------------------------------------------------------------------------------
  340.     CContainerSelection::AddSiblingFrame
  341. ----------------------------------------------------------------------------------------*/
  342.  
  343. void CContainerSelection::AddSiblingFrame (Environment* ev)
  344. {
  345.     CBaseContent* selectedProxies = (CBaseContent*) GetSelectedContent (ev);
  346.     CContentProxyIterator proxies (selectedProxies);
  347.     for (CProxy* proxy = proxies.First(); proxies.IsNotComplete(); proxy = proxies.Next()) {
  348.         CContainerFrame* embeddingFrame;
  349.         FW_CAcquiredODFrame subFrame;
  350.         FW_CAcquiredODShape suggestedShape;
  351.         FW_CAcquiredODPart subPart;
  352.         embeddingFrame = FW_DYNAMIC_CAST (CContainerFrame, GetPart(ev)->GetLastActiveFrame(ev)); // XXX not right
  353.         subFrame = proxy->AcquireEmbeddedFrame (ev, embeddingFrame);
  354.         FW_CRect currentBounds = proxy->GetBounds (ev);
  355.         FW_CRect newBounds (FW_kFixed0, FW_kFixed0, currentBounds.Width(), currentBounds.Height());
  356.         suggestedShape = ::FW_NewODShape (ev, newBounds);
  357.         subPart = proxy->AcquireEmbeddedPart (ev);
  358.         embeddingFrame->EmbeddedFrameRequested (ev, proxy, subFrame,
  359.             suggestedShape, subPart, subFrame->GetViewType(ev),
  360.             subFrame->GetPresentation(ev), subFrame->GetFrameGroup(ev),
  361.             false, false);
  362.     }
  363. }
  364.  
  365. //----------------------------------------------------------------------------------------
  366. //    CContainerSelection::SelectAll
  367. //----------------------------------------------------------------------------------------
  368.  
  369. void CContainerSelection::SelectAll(Environment* ev)
  370. {    
  371.     CContainerFrame* activeFrame = (CContainerFrame*)fContainerPart->GetLastActiveFrame(ev);
  372.     
  373.     RenderAllHandles(ev, activeFrame);
  374.  
  375.     CContentProxyIterator ite(fContainerPart->GetPartContent());
  376.     for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  377.     {
  378.         if (!proxy->IsSelected())
  379.             DoAdd(ev, proxy);
  380.     }
  381.     
  382.     RenderAllHandles(ev, activeFrame);
  383. }
  384.  
  385. //----------------------------------------------------------------------------------------
  386. //    CContainerSelection::IsEmpty
  387. //----------------------------------------------------------------------------------------
  388.  
  389. FW_Boolean CContainerSelection::IsEmpty(Environment* ev) const
  390. {    
  391. FW_UNUSED(ev);
  392.     return fCount == 0;
  393. }
  394.  
  395. //----------------------------------------------------------------------------------------
  396. //    CContainerSelection::CenterSelection
  397. //----------------------------------------------------------------------------------------
  398.  
  399. FW_CPoint CContainerSelection::CenterSelection(Environment* ev, FW_CFrame* scopeFrame)
  400. {
  401.     FW_ASSERT(scopeFrame);
  402.     
  403.     FW_CRect bounds = scopeFrame->GetContentView(ev)->GetBoundsInContent(ev);
  404.     FW_CRect dragRect = GetDragRect(ev);
  405.     FW_CRect box(dragRect);
  406.     box.PlaceInCenterOf(bounds);
  407.             
  408.     FW_CPoint result(box.left - dragRect.left, box.top - dragRect.top);
  409.     OffsetSelection(ev, result.x, result.y);
  410.     
  411.     GetPresentation(ev)->Invalidate(ev, GetUpdateShape(ev));
  412.  
  413.     return result;
  414. }
  415.  
  416. //----------------------------------------------------------------------------------------
  417. //    CContainerSelection::Resize
  418. //----------------------------------------------------------------------------------------
  419.  
  420. FW_Boolean CContainerSelection::Resize(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  421. {    
  422.     if (fClickedHandle == 0)
  423.         return FALSE;
  424.         
  425.     if (!this->IsOKtoEdit(ev))    // can't resize read only part
  426.     {
  427.         FW_Beep();
  428.         return TRUE;
  429.     }
  430.                 
  431.     if (!theMouseEvent.WaitUntilMouseMoved(ev))
  432.         return TRUE;
  433.     
  434.     ODFacet* facet = theMouseEvent.GetFacet(ev);
  435.     CContainerFrame* frame = (CContainerFrame*)FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  436.  
  437.     CProxy* anchorProxy = GetAnchorProxy();
  438.     
  439.     FW_CInk resizeInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
  440.     FW_CStyle resizeStyle(FW_kFixed0, FW_kGrayPat);
  441.     
  442.     CResizeTracker resizeTracker(ev, frame->GetContentView(ev), facet, anchorProxy, fClickedHandle, resizeInk, resizeStyle);
  443.     if (resizeTracker.Track(ev, theMouseEvent))
  444.     {
  445.         GetPresentation(ev)->Invalidate(ev, GetUpdateShape(ev));
  446.  
  447.         FW_CPoint lastLocation;
  448.         resizeTracker.GetLastLocation(lastLocation);
  449.         FW_CRect srcRect, dstRect;
  450.         anchorProxy->GetMappedRects(fClickedHandle, lastLocation, srcRect, dstRect);
  451.  
  452.         CResizeCommand* cmd = FW_NEW(CResizeCommand,
  453.                                         (ev, fContainerPart, frame, this,
  454.                                          srcRect, dstRect));
  455.         cmd->Execute(ev);
  456.     }
  457.     else
  458.     {
  459.         FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
  460.  
  461.         FW_Fixed penSize = CalcHandlePenSize(frame->GetZoomFactor());
  462.         anchorProxy->CalcHandle(fClickedHandle, &fWorkingHandle, penSize);
  463.         fWorkingHandle.Render(vc);    // redraw the handle
  464.     }
  465.     
  466.     return TRUE;
  467. }
  468.  
  469. //----------------------------------------------------------------------------------------
  470. //    CContainerSelection::CalcCache
  471. //----------------------------------------------------------------------------------------
  472.  
  473. void CContainerSelection::CalcCache(Environment* ev)
  474. {
  475.     fDragRect.Clear();
  476.     
  477.     if (fUpdateShape == NULL)
  478.         fUpdateShape = ::FW_NewODShape(ev);
  479.     
  480.     if (fCount == 0)
  481.         return;
  482.     
  483.     FW_CAcquiredODShape aqTempShape = ::FW_NewODShape(ev);
  484.     FW_CRect tempRect;
  485.  
  486.     FW_Boolean first = TRUE;
  487.     CContentProxyIterator ite(fSelectionContent);
  488.     for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  489.     {
  490.         tempRect = proxy->GetBounds(ev);
  491.         proxy->GetUpdateBox(ev, aqTempShape);
  492.         if (first)
  493.         {
  494.             fDragRect = tempRect;
  495.             fUpdateShape->CopyFrom(ev, aqTempShape);
  496.         }
  497.         else
  498.         {
  499.             fDragRect |= tempRect;
  500.             fUpdateShape->Union(ev, aqTempShape);
  501.         }
  502.         proxy->SetHasChanged(FALSE);
  503.                         
  504.         first = FALSE;
  505.     }
  506. }
  507.  
  508. //----------------------------------------------------------------------------------------
  509. //    CContainerSelection::AcquireSelectionShape
  510. //----------------------------------------------------------------------------------------
  511.  
  512. ODShape* CContainerSelection::AcquireSelectionShape(Environment* ev, ODFacet* facet, FW_CFrame* frame)
  513. {
  514. FW_UNUSED(frame);
  515. FW_UNUSED(facet);
  516.  
  517.     return ::FW_NewODShape(ev, GetDragRect(ev));
  518. }
  519.  
  520. //----------------------------------------------------------------------------------------
  521. //    CContainerSelection::AcquireSelectionOutline
  522. //----------------------------------------------------------------------------------------
  523.  
  524. ODShape* CContainerSelection::AcquireSelectionOutline(Environment* ev, ODFacet* facet, FW_CFrame* frame)
  525. {
  526.     FW_ASSERT(GetAnchorProxy());
  527.     
  528.     FW_CAcquiredODShape outline = GetAnchorProxy()->CreateProxyOutline(ev);
  529.  
  530.     if (fCount > 1)
  531.     {
  532.         FW_CAcquiredODShape shapeOutline = FW_CSelection::AcquireSelectionOutline(ev, facet, frame);
  533.         outline->Union(ev, shapeOutline);
  534.     }
  535.  
  536.     return outline.Orphan();
  537. }
  538.  
  539. //----------------------------------------------------------------------------------------
  540. //    CContainerSelection::OffsetSelection
  541. //----------------------------------------------------------------------------------------
  542.  
  543. void CContainerSelection::OffsetSelection(Environment* ev, FW_Fixed xDelta, FW_Fixed yDelta)
  544. {
  545.     FW_CAcquiredODShape aqUnionShape(GetUpdateShape(ev)->Copy(ev));
  546.     
  547.     CContentProxyIterator ite(fSelectionContent);
  548.     for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  549.     {
  550.         proxy->OffsetProxy(ev, xDelta, yDelta);
  551.     }
  552.     
  553.     aqUnionShape->Union(ev, GetUpdateShape(ev));
  554.     
  555.     FW_CFacetClipper facetClipper;
  556.     facetClipper.Clip(ev, GetPresentation(ev), aqUnionShape);
  557. }
  558.  
  559. //----------------------------------------------------------------------------------------
  560. //    CContainerSelection::SelectWithRectangle
  561. //----------------------------------------------------------------------------------------
  562.  
  563. void CContainerSelection::SelectWithRectangle(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  564. {
  565.     FW_CStyle trackStyle(FW_kFixed0, FW_kAntPat);
  566.     FW_CInk trackInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
  567.     CTrackRect rectShape(trackInk, trackStyle);    // Create a rect shape on the stack
  568.     
  569.     ODFacet* facet = theMouseEvent.GetFacet(ev);
  570.     FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  571.  
  572.     CSelectTracker tracker(ev, frame->GetContentView(ev), facet, &rectShape);
  573.     if (tracker.Track(ev, theMouseEvent))
  574.     {
  575.         FW_Boolean isShift = theMouseEvent.IsExtendModifier(ev);
  576.         FW_CRect selectRect;
  577.         rectShape.GetRectBounds(selectRect);
  578.         
  579.         CContentProxyIterator ite(fContainerPart->GetPartContent());
  580.         for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  581.         {
  582.             if (proxy->InSelectionRect(selectRect))
  583.             {
  584.                 if (proxy->IsSelected())
  585.                 {
  586.                     if (isShift)
  587.                     {
  588.                         DoRemove(ev, proxy);
  589.                         RenderHandles(ev, proxy);        // Turn Off
  590.                     }
  591.                 }
  592.                 else
  593.                 {
  594.                     DoAdd(ev, proxy);
  595.                     RenderHandles(ev, proxy);    // Turn on    
  596.                 }
  597.             }
  598.             else if (proxy->IsSelected() && !isShift)
  599.             {
  600.                 DoRemove(ev, proxy);
  601.                 RenderHandles(ev, proxy);        // Turn Off
  602.             }
  603.         }            
  604.     }
  605.     else
  606.     {
  607.         if (!theMouseEvent.IsExtendModifier(ev))
  608.             CloseSelection(ev);
  609.     }
  610. }
  611.  
  612. //----------------------------------------------------------------------------------------
  613. //    CContainerSelection::IsMouseInDraggableItem
  614. //----------------------------------------------------------------------------------------
  615.  
  616. FW_Boolean CContainerSelection::IsMouseInDraggableItem(Environment* ev, 
  617.                                                   FW_CFrame* frame, 
  618.                                                   const FW_CMouseEvent& theMouseEvent, 
  619.                                                   FW_Boolean inBackground)
  620. {    
  621. FW_UNUSED(inBackground);
  622.     fClickedHandle = 0;
  623.     fAnchorProxy = NULL;
  624.  
  625.     FW_CViewContext vc(ev, frame->GetContentView(ev), theMouseEvent.GetFacet(ev));
  626.  
  627.     // ----- Look first for a handle -----
  628.     FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  629.     frame->GetContentView(ev)->FrameToViewContent(ev, where);
  630.  
  631.     CProxy* clickedProxy = WhichHandle(ev, vc, where, fClickedHandle, ((CContainerFrame*)frame)->GetZoomFactor());
  632.     if (clickedProxy != NULL)
  633.     {
  634.         fAnchorProxy = clickedProxy;
  635.         return FALSE;            // if in a handle we won't drag
  636.     }
  637.     
  638.     // ----- then look for a selected proxy -----
  639.     CProxy* proxy = fContainerPart->WhichProxy(ev, vc, where, TRUE);
  640.     
  641.     if (proxy != NULL && proxy->IsSelected())
  642.     {
  643.         fAnchorProxy = proxy;
  644.         return TRUE;
  645.     }
  646.     
  647.     return FALSE;
  648. }
  649.  
  650. //----------------------------------------------------------------------------------------
  651. // CContainerSelection::UpdateSelectionOnMouseDown
  652. //----------------------------------------------------------------------------------------
  653.  
  654. void CContainerSelection::UpdateSelectionOnMouseDown(Environment* ev, 
  655.                                             const FW_CMouseEvent& mouseEvent,
  656.                                             ODFacet* embeddedFacet,
  657.                                             FW_Boolean inEmbeddedFrameBorder,
  658.                                             FW_Boolean inBackground)
  659. {
  660.     if (inEmbeddedFrameBorder)
  661.     {
  662.         fClickedHandle = 0;
  663.         fAnchorProxy = NULL;
  664.  
  665.         CProxy* theProxy = (CProxy*)fContainerPart->GetProxy(ev, embeddedFacet->GetFrame(ev));
  666.         FW_ASSERT(theProxy);
  667.         
  668.         if (!theProxy->IsSelected())
  669.             AddToSelection(ev, theProxy, TRUE);
  670.                 
  671.         fAnchorProxy = theProxy;
  672.     }
  673.     else
  674.     {
  675.         ODFacet* facet =  mouseEvent.GetFacet(ev);
  676.         FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  677.         FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
  678.         FW_CPoint where = mouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  679.         frame->GetContentView(ev)->FrameToViewContent(ev, where);
  680.         
  681.         CProxy* clickedProxy = fContainerPart->WhichProxy(ev, vc, where, FALSE);
  682.         if (clickedProxy)
  683.         {
  684.             if (mouseEvent.IsExtendModifier(ev))
  685.             {
  686.                 if (clickedProxy->IsSelected())
  687.                 {
  688.                     RemoveFromSelection(ev, clickedProxy, !inBackground);
  689.                     if (clickedProxy == fAnchorProxy)
  690.                         fAnchorProxy = NULL;
  691.                 }
  692.                 else
  693.                 {
  694.                     AddToSelection(ev, clickedProxy, !inBackground);
  695.                     fAnchorProxy = clickedProxy;
  696.                 }
  697.             }
  698.             else if (!clickedProxy->IsSelected())
  699.             {
  700.                 fAnchorProxy = clickedProxy;
  701.                 CloseSelection(ev);
  702.                 AddToSelection(ev, clickedProxy, !inBackground);
  703.             }    
  704.         }
  705.     }
  706. }
  707.  
  708. //----------------------------------------------------------------------------------------
  709. //    CContainerSelection::DeleteSelection
  710. //----------------------------------------------------------------------------------------
  711.  
  712. void CContainerSelection::DeleteSelection(Environment* ev)
  713. {
  714.     CProxy* proxy;
  715.     while ((proxy = fSelectionContent->GetFirstProxy()) != NULL)
  716.     {
  717.         DoRemove(ev, proxy);                        // Remove from selection
  718.         fContainerPart->DeleteProxy(ev, proxy);        // delete the proxy
  719.     }
  720. }
  721.  
  722. //----------------------------------------------------------------------------------------
  723. //    CContainerSelection::IsOKtoEdit
  724. //----------------------------------------------------------------------------------------
  725.  
  726. FW_Boolean CContainerSelection::IsOKtoEdit(Environment* ev)
  727. {
  728.     // Check for a read-only part
  729.     if (fContainerPart->IsReadOnly(ev))
  730.         return false;
  731.  
  732.     return true;
  733. }
  734.  
  735. //----------------------------------------------------------------------------------------
  736. //    CContainerSelection::SelectContent
  737. //----------------------------------------------------------------------------------------
  738. void CContainerSelection::SelectContent(Environment* ev, CBaseContent* content)
  739. {
  740.     this->CloseSelection(ev);
  741.  
  742.     CContentProxyIterator it(content);
  743.     for (CProxy* proxy = it.First(); it.IsNotComplete(); proxy = it.Next())
  744.     {
  745.         this->AddToSelection(ev, proxy, TRUE);
  746.     }
  747. }
  748.  
  749. //----------------------------------------------------------------------------------------
  750. //    CContainerSelection::GetSelectionContent
  751. //----------------------------------------------------------------------------------------
  752.  
  753. CBaseContent* CContainerSelection::GetSelectionContent(Environment* ev)
  754. {
  755. FW_UNUSED(ev);
  756.     return fSelectionContent;
  757. }
  758.  
  759. //----------------------------------------------------------------------------------------
  760. //    CContainerSelection::Count
  761. //----------------------------------------------------------------------------------------
  762.  
  763. unsigned long CContainerSelection::Count() const
  764. {
  765.     return fSelectionContent->CountProxies();
  766. }
  767.  
  768. //----------------------------------------------------------------------------------------
  769. //    CContainerSelection::GetFirstSelectedProxy
  770. //----------------------------------------------------------------------------------------
  771.  
  772. CProxy* CContainerSelection::GetFirstSelectedProxy() const
  773. {
  774.     return fSelectionContent->GetFirstProxy();
  775. }
  776.  
  777. //----------------------------------------------------------------------------------------
  778. //    CContainerSelection::IsSelectedShapesChanged
  779. //----------------------------------------------------------------------------------------
  780.  
  781. FW_Boolean CContainerSelection::IsSelectedShapesChanged(Environment *ev) const
  782. {
  783.     CContentProxyIterator ite(fSelectionContent);
  784.     for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  785.     {
  786.         if (proxy->HasChanged())
  787.         {
  788.             ((CContainerSelection*)this)->ClearCache(ev);
  789.             return TRUE;
  790.         }
  791.     }
  792.     
  793.     return FALSE;
  794. }
  795.  
  796. //----------------------------------------------------------------------------------------
  797. //    CContainerSelection::ClearCache
  798. //----------------------------------------------------------------------------------------
  799.  
  800. void CContainerSelection::ClearCache(Environment *ev)
  801. {
  802.     if (fUpdateShape)
  803.         fUpdateShape->Release(ev);
  804.     fUpdateShape = NULL;
  805. }
  806.  
  807. //----------------------------------------------------------------------------------------
  808. //    CContainerSelection::GetUpdateShape
  809. //----------------------------------------------------------------------------------------
  810.  
  811. ODShape* CContainerSelection::GetUpdateShape(Environment *ev) const
  812. {        
  813.     if (fUpdateShape == NULL || IsSelectedShapesChanged(ev))
  814.         ((CContainerSelection*)this)->CalcCache(ev);
  815.     
  816.     return fUpdateShape;
  817. }
  818.  
  819. //----------------------------------------------------------------------------------------
  820. //    CContainerSelection::GetDragRect
  821. //----------------------------------------------------------------------------------------
  822.  
  823. FW_CRect CContainerSelection::GetDragRect(Environment *ev) const
  824. {        
  825.     if (fUpdateShape == NULL || IsSelectedShapesChanged(ev))
  826.         ((CContainerSelection*)this)->CalcCache(ev);
  827.  
  828.     return fDragRect;
  829. }
  830.  
  831. //----------------------------------------------------------------------------------------
  832. //    CContainerSelection::CanPasteAsLink
  833. //----------------------------------------------------------------------------------------
  834.  
  835. FW_Boolean  CContainerSelection::CanPasteAsLink(Environment*,  ODPasteAsMergeSetting& setting,  ODStorageUnit*)
  836. {
  837.     setting = kODPasteAsEmbedOnly;
  838.     return fAllowLink;
  839. }
  840.  
  841.